package com.example.demo.pipeline.service.impl;

import com.example.demo.pipeline.context.TemplateContext;
import com.example.demo.pipeline.executor.TemplateExecutor;
import com.example.demo.pipeline.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author liyuncong
 * @version 1.0
 * @file TemplateServiceImpl
 * @brief TemplateServiceImpl
 * @details TemplateServiceImpl
 * @date 2022-11-03
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-11-03                  liyuncong          Created
 */
@Service
public class TemplateServiceImpl implements TemplateService {

    @Autowired
    private TemplateExecutor templateExecutor;

    @Override
    public void sendText(Map<String, String> dataMap) {
        final TemplateContext context = convert(dataMap);
        templateExecutor.executor(context);
    }

    private TemplateContext convert(Map<String, String> dataMap) {
        final TemplateContext context = new TemplateContext();
        context.setTemplateName(dataMap.get("name"));
        return context;
    }
}
